import { defineStore } from "pinia";
import { ref } from "vue";

// export const useAlertsStore = defineStore('login', {
//    return { username,password}
  
// })
export const useUserStore = defineStore('login', () => {
   const username = ref('')
   const password = ref('')
   
   const login = (user, pass) => {
      return new Promise((resolve, reject) => {
         // 模拟异步请求
         setTimeout(() => {
            if (user === 'admin' && pass === '123456') {
               username.value = user
               password.value = pass
               resolve('登录成功')
            } else {
               reject('用户名或密码错误')
            }
         }, 1000)
      })
   }
   return { username,password,login }

 
 }, {
     // 持久化
  persist:{
   enabled:true,// 存储全部数据
   key:'userinfor',//关键字
   Storage:localStorage,
 }
})
 